package com.ruoyi.project.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.erp.dto.TaskMemberQuery;
import com.ruoyi.project.erp.vo.TaskMemberListVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.erp.domain.TaskMember;
import com.ruoyi.project.erp.service.ITaskMemberService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 任务成员Controller
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@RestController
@RequestMapping("/erp/taskMember")
public class TaskMemberController extends BaseController
{
    @Autowired
    private ITaskMemberService taskMemberService;

    /**
     * 查询任务成员列表
     */
    @PreAuthorize("@ss.hasPermi('erp:taskMember:list')")
    @GetMapping("/list")
    // 参数类型修改为 TaskMemberQuery
    public TableDataInfo list(TaskMemberQuery query)
    {
        startPage();
        // 调用Service层新方法，返回类型为 List<TaskMemberListVO>
        List<TaskMemberListVO> list = taskMemberService.selectList(query);
        return getDataTable(list);
    }


    /**
     * 导出任务成员列表
     */
    @PreAuthorize("@ss.hasPermi('erp:taskMember:export')")
    @Log(title = "任务成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskMember taskMember)
    {
        List<TaskMember> list = taskMemberService.selectTaskMemberList(taskMember);
        ExcelUtil<TaskMember> util = new ExcelUtil<TaskMember>(TaskMember.class);
        util.exportExcel(response, list, "任务成员数据");
    }

    /**
     * 获取任务成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:taskMember:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskMemberService.selectTaskMemberById(id));
    }

    /**
     * 新增任务成员
     */
    @PreAuthorize("@ss.hasPermi('erp:taskMember:add')")
    @Log(title = "任务成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskMember taskMember)
    {
        return toAjax(taskMemberService.insertTaskMember(taskMember));
    }

    /**
     * 修改任务成员
     */
    @PreAuthorize("@ss.hasPermi('erp:taskMember:edit')")
    @Log(title = "任务成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskMember taskMember)
    {
        return toAjax(taskMemberService.updateTaskMember(taskMember));
    }

    /**
     * 删除任务成员
     */
    @PreAuthorize("@ss.hasPermi('erp:taskMember:remove')")
    @Log(title = "任务成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskMemberService.deleteTaskMemberByIds(ids));
    }
}
